package com.briup.jz.service.impl;

import com.briup.jz.bean.Address;
import com.briup.jz.dao.AddressMapper;
import com.briup.jz.dao.extend.AddressExtendMapper;
import com.briup.jz.service.IAddressService;
import com.briup.jz.utils.CustomerException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName: jz
 * @Author: xjs
 * @Description: 地址业务实现
 * @Date: 2020/6/14 16:13
 */
@Service
public class AddressServiceImpl implements IAddressService {

    @Resource
    private AddressMapper addressMapper;
    @Resource
    private AddressExtendMapper addressExtendMapper;

    @Override
    public void saveOrUpdate(Address address) {
        if(address.getId() == null){
            addressMapper.insert(address);
        }
        addressMapper.updateByPrimaryKey(address);
    }

    @Override
    public void deleteById(Long id) throws CustomerException {
        Address address = addressMapper.selectByPrimaryKey(id);
        if (address == null){
            throw new CustomerException("数据不存在");
        }
        addressMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Address> findAllByUserid(Long id) {
        return addressExtendMapper.selectByUserid(id);
    }
}
